package com.pdwl.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pdwl.common.dtos.PageRequestDto;
import com.pdwl.common.dtos.PageResponseResult;
import com.pdwl.common.enums.AppHttpCodeEnum;
import com.pdwl.common.exception.CustomException;
import com.pdwl.common.vo.OrderVo;
import com.pdwl.mapper.OrderMapper;
import com.pdwl.pojo.Order;
import com.pdwl.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: TLB
 * @Date: 2023/1/12 20:35
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 根据条件分页查询
     * @param pageRequestDto
     * @return
     */
    @Override
    public PageResponseResult<List<OrderVo>> pageByOrder(PageRequestDto<Order> pageRequestDto) {

        if (pageRequestDto==null){
            throw new CustomException(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        pageRequestDto.checkParam();
        // 分页查询
        PageHelper.<OrderVo>startPage(pageRequestDto.getPage(), pageRequestDto.getSize());
        List<OrderVo> orderVos = orderMapper.selectByOrder(pageRequestDto.getEntity());
        PageInfo<OrderVo> pageInfo = new PageInfo<>(orderVos);
        return PageResponseResult.success(pageInfo);
    }
}
